<?php
/**
 * Created by PhpStorm.
 * User: Liulibao
 * Date: 2020/1/4
 * Time: 12:09
 */

namespace app\home\controller;


use app\common\model\Member;
use think\Lang;

class Sellermember extends BaseSeller
{
    public function _initialize() {
        parent::_initialize();
        Lang::load(APP_PATH . 'home/lang/'.config('default_lang').'/sellermember.lang.php');
    }

    // 首页  店铺id 8  会员id 17  array(2) { ["invite_store_id"]=> int(8) ["member_type"]=> int(0) }
    public function index()
    {
        $member_model = new Member();
        //会员级别
        $member_grade = $member_model->getMemberGradeArr();
        $search_field_value = input('search_field_value');
        $search_field_name = input('search_field_name');
        $start_time = input('start_time');
        $end_time = input('end_time');
        $search_type = input('search_type');

        $invite_code = input('invite_code');
        $condition = array(
        );
        if ($start_time) {
            $start_time = strtotime($start_time);
            $end_time = $end_time ? strtotime($end_time) : '';
            $condition['member_addtime'] = ['between', [$start_time, $end_time]];
        }
        if ($search_type != '') {
            $condition['member_state'] = $search_type;
        }
        if ($search_field_value != '') {
            switch ($search_field_name) {
               /*  case 'member_name':
                    $condition['member_name'] = array('like', '%' . trim($search_field_value) . '%');
                    break;
               case 'member_email':
                    $condition['member_email'] = array('like', '%' . trim($search_field_value) . '%');
                    break;
                case 'member_mobile':
                    $condition['member_mobile'] = array('like', '%' . trim($search_field_value) . '%');
                    break;
                case 'member_truename':
                    $condition['member_truename'] = array('like', '%' . trim($search_field_value) . '%');
                    break;*/
                case 'seller_name':
                    $condition['invite_name'] = trim($search_field_value);
                    break;
             case 'enterprise_name':
                    $condition['enterprise_name'] = trim($search_field_value);
                    break;
            }
        }

        if(!empty($invite_code)) {
            $condition['invite_code'] = $invite_code;
        }

        $condition['invite_store_id'] = $_SESSION['home']['store_id'];
        $condition['member_type'] = 0;

        $member_list = $member_model->getMemberList($condition, '*', 10, 'member_id desc');

        $this->assign('member_grade', $member_grade);
        $this->assign('search_field_name', trim($search_field_name));
        $this->assign('search_field_value', trim($search_field_value));
        $this->assign('invite_code', trim($invite_code));
        $this->assign('member_list', $member_list);
//        $this->assign('member_type', member_type());
        $this->assign('show_page', $member_model->page_info->render());
        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellermember');
        /* 设置卖家当前栏目 */
        $this->setSellerCurItem('member_index');
        return $this->fetch($this->template_dir.'index');
    }


    /**
     *    栏目菜单
     */
    function getSellerItemList() {
        $menu_array[] = array(
            'name' => 'member_index',
            'text' => lang('member_index'),
            'url' => url('Sellermember/index'),
        );

        if (request()->action() === 'account_add') {
            $menu_array[] = array(
                'name' => 'account_add',
                'text' => lang('add_account'),
                'url' => url('Selleraccount/account_add'),
            );
        }
        if (request()->action() === 'group_edit') {
            $menu_array[] = array(
                'name' => 'account_edit',
                'text' => lang('edit_account'),
                'url' => 'javascript:void(0)',
            );
        }

        return $menu_array;
    }

}
